<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/addons/hc_answer/template/css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="/addons/hc_answer/template/plugins/font-awesome/css/font-awesome.css">
		<link rel="stylesheet" href="/addons/hc_answer/template/css/table.css" />
		<link rel="shortcut icon" href="./resource/images/favicon.ico" />
		<link href="./resource/css/bootstrap.min.css?v=20170915" rel="stylesheet">
		<link href="./resource/css/common.css?v=20170915" rel="stylesheet">
		<script type="text/javascript">
			if(navigator.appName == 'Microsoft Internet Explorer'){
				if(navigator.userAgent.indexOf("MSIE 5.0")>0 || navigator.userAgent.indexOf("MSIE 6.0")>0 || navigator.userAgent.indexOf("MSIE 7.0")>0) {
					alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
				}
			}
			window.sysinfo = {
				{if !empty($_W['uniacid'])}'uniacid': '{$_W['uniacid']}',{/if}
				{if !empty($_W['acid'])}'acid': '{$_W['acid']}',{/if}
				{if !empty($_W['openid'])}'openid': '{$_W['openid']}',{/if}
				{if !empty($_W['uid'])}'uid': '{$_W['uid']}',{/if}
				'isfounder': {if !empty($_W['isfounder'])}1{else}0{/if},
				'family': '{IMS_FAMILY}',
				'siteroot': '{$_W['siteroot']}',
				'siteurl': '{$_W['siteurl']}',
				'attachurl': '{$_W['attachurl']}',
				'attachurl_local': '{$_W['attachurl_local']}',
				'attachurl_remote': '{$_W['attachurl_remote']}',
				'module' : {'url' : '{if defined('MODULE_URL')}{MODULE_URL}{/if}', 'name' : '{if defined('IN_MODULE')}{IN_MODULE}{/if}'},
				'cookie' : {'pre': '{$_W['config']['cookie']['pre']}'},
				'account' : {php echo json_encode($_W['account'])},
				'server' : {'php' : '{php echo phpversion()}'},
			};
		</script>
		<script>var require = { urlArgs: 'v=20170915' };</script>
		<script type="text/javascript" src="./resource/js/lib/jquery-1.11.1.min.js"></script>
		<script type="text/javascript" src="./resource/js/lib/bootstrap.min.js"></script>
		<script type="text/javascript" src="./resource/js/app/util.js?v=20170915"></script>
		<script type="text/javascript" src="./resource/js/app/common.min.js?v=20170915"></script>
		<script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
		<style type="text/css">
			body{
				background-color:#fff;
				min-width: 100%;
			}
			.layui-form-pane .layui-form-label{
				width: 120px
			}
			.input-group .form-control{
				width:430px;
			}
			legend{
				width:10%;
			}
		</style>
	</head>

	<body>
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field">
  				<legend>编辑物品</legend>
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
					<div class="layui-tab-content" >
						<!-- 基础设置 开始-->
						<form class="layui-form  layui-form-pane" action="" id="form">
							<div class="layui-form-item">
							    <label class="layui-form-label">物品名称</label>
							    <div class="layui-input-inline">
							      <input type="text" name="name" value="{$info['name']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">物品图标</label>
								<div class="layui-input-inline">
									{php echo tpl_form_field_image('thumbs',$info['thumb']);}
								</div>
							</div>
							<div class="layui-form-item putong else">
							    <label class="layui-form-label">使用中图标</label>
								<div class="layui-input-inline">
									{php echo tpl_form_field_image('usethumb',$info['usethumb']);}
									<span style="color:red">排位赛列表页右上角物品使用中图片</span>
								</div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">物品类型</label>
							    <div class="layui-input-block">
							    	<input type="radio" lay-filter="types" name="type" value="1" title="宝箱" {if $info['type']==1}checked="checked"{/if}>
							    	<input type="radio" lay-filter="types" name="type" value="2" title="新手礼包" {if $info['type']==2}checked="checked"{/if}>
							    	<input type="radio" lay-filter="types" name="type" value="3" title="金币卡" {if $info['type']==3}checked="checked"{/if}>
							    	<input type="radio" lay-filter="types" name="type" value="4" title="知识书" {if $info['type']==4}checked="checked"{/if}>
							    	<input type="radio" lay-filter="types" name="type" value="5" title="限次卡" {if $info['type']==5}checked="checked"{/if}>
							    	<input type="radio" lay-filter="types" name="type" value="6" title="限时卡" {if $info['type']==6}checked="checked"{/if}>
							    	<input type="radio" lay-filter="types" name="type" value="7" title="加分卡" {if $info['type']==7}checked="checked"{/if}>
							    </div>
							</div>
							<div class="layui-form-item newthumb">
							    <label class="layui-form-label">新手礼包图片</label>
								<div class="layui-input-inline" >
									{php echo tpl_form_field_image('newthumbs',$info['newthumb']);}
									<span style="color:red">建议尺寸900*305</span>
								</div>
							</div>
							<div class="layui-form-item putong else  xs xc" style="color:red">
							      温馨提示：限时卡和限次卡不能同时填写经验和金币！<br/>
							      如：限次经验卡，填写场次和经验；限时经验卡，填写时间和经验
							</div>
							<div class="layui-form-item putong else changci">
							    <label class="layui-form-label">场次 [次]</label>
							    <div class="layui-input-inline">
							      <input type="num" name="cc" value="{$info['cc']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger ">
							    </div>
							</div>
							<div class="layui-form-item putong else time">
							    <label class="layui-form-label">时间 [时]</label>
							    <div class="layui-input-inline">
							      <input type="num" name="sj" value="{$info['sj']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger ">
							    </div>
							</div>
							<div class="layui-form-item putong gold">
							    <label class="layui-form-label">金币 [个]</label>
							    <div class="layui-input-inline">
							      <input type="num" name="jbs" value="{$info['jb']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger ">
							    </div>
							</div>
							<div class="layui-form-item putong else xs xc">
							    <label class="layui-form-label">金币 [%]</label>
							    <div class="layui-input-inline">
							      <input type="num" name="jb" value="{$info['jb']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger ">
							    </div>
							</div>
							<div class="layui-form-item putong else  xs xc">
							    <label class="layui-form-label">经验 [%]</label>
							    <div class="layui-input-inline">
							      <input type="num" name="jy" value="{$info['jy']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger ">
							    </div>
							</div>
							<div class="layui-form-item putong else jf">
							    <label class="layui-form-label">加分 [%]</label>
							    <div class="layui-input-inline">
							      <input type="num" name="jf" value="{$info['jf']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger ">
							    </div>
							</div>

							<div class="layui-form-item">
							    <label class="layui-form-label">商城展示</label>
							    <div class="layui-input-block">
							    	<input type="radio" lay-filter="shop" name="shop" value="1" title="显示" {if $info['shop']==1}checked="checked"{/if}>
							    	<input type="radio" lay-filter="shop" name="shop" value="0" title="不显示" {if $info['shop']==0}checked="checked"{/if}>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">排位展示</label>
							    <div class="layui-input-block">
							    	<input type="radio" lay-filter="dan" name="dan" value="1" title="显示" {if $info['dan']==1}checked="checked"{/if}>
							    	<input type="radio" lay-filter="dan" name="dan" value="0" title="不显示" {if $info['dan']==0}checked="checked"{/if}>
							    </div>
							</div>
							<div class="layui-form-item price">
							    <label class="layui-form-label">价格 [元]</label>
							    <div class="layui-input-inline">
							      <input type="num" name="price" value="{$info['price']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">允许赠送</label>
							    <div class="layui-input-block">
							    	<input type="radio" name="give" value="1" title="允许" {if $info['give']==1}checked="checked"{/if}>
							    	<input type="radio" name="give" value="0" title="不允许" {if $info['give']==0}checked="checked"{/if}>
							    </div>
							</div>
							<div class="layui-form-item box">
							    <label class="layui-form-label">随机数量</label>
							    <div class="layui-input-inline">
							      <input type="num" name="randnum" value="{$info['randnum']}" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item layui-form-text">
							    <label class="layui-form-label">物品描述</label>
							    <div class="layui-input-block">
							      <textarea name="desc" placeholder="请输入内容" class="layui-textarea">{$info['desc']}</textarea>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">排序</label>
							    <div class="layui-input-inline">
							      <input type="num" name="sort" value="{$info['sort']}" placeholder="50" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item box" id="selprop">
							    <label class="layui-form-label">设置物品</label>
							    <div class="layui-input-inline">
									<a href="javascript:;" class="layui-btn" id="addlibrary">
										<i class="layui-icon"></i> 选择物品
									</a>
									<input type="hidden" name="remark" id="remark" value="{$info['remark']}" >
								</div>
							</div>
							<fieldset class="layui-elem-field box">
  								<legend>已选物品</legend>
								<div class="layui-field-box ">
									<table class="site-table table-hover">
										<thead>
											<tr>
												<th>物品名称</th>
												<th>物品图标</th>
												<th>场次</th>
												<th>限时</th>
												<th>金币</th>
												<th>经验</th>
												<th>价格</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											{loop $info['res'] $v}
											<tr>
										      	<td>{$v['name']}</td>
										      	<td><img style="width:50px" src="{$v['thumb']}"></td>
										      	<td>{$v['cc']}</td>
										      	<td>{$v['sj']}</td>
										      	<td>{$v['jb']}</td>
										      	<td>{$v['jy']}</td>
										      	<td>{$v['price']}</td>
										      	<td><a href="javascript:;" data-id="{$v['id']}" class="layui-btn layui-btn-danger layui-btn-mini del">删除</a></td>
										    </tr>
										    {/loop}
										</tbody>
										<tfoot>
											<tr>
												<th colspan="8" style="color:red">删除操作后，点击下方提交按钮</th>
											</tr>
										</tfoot>
									</table>
								</div>
							</fieldset>
							<input type="hidden" name="id" value="{$info['id']}" >
							<div class="layui-form-item">
							    <div class="layui-input-block">
							      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="rankadd" style="pointer-events: auto;">提交</button>
							      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
							    </div>
							</div>

							</form>
						<!-- 题目设置 结束-->
					</div>
				</div>
			</fieldset>
		</div>

		<script type="text/javascript" src="/addons/hc_answer/template/plugins//layui/layui.js"></script>
		<script>
			layui.use(['form','upload','laypage','layer'], function() {
				var $ = layui.jquery,
				upload = layui.upload,
				form = layui.form();
				form.render();

				var typeck = $("input[name='type']:checked").val();

				if(typeck==1){
					$(".box").show();
					$(".newthumb").hide();
					$(".putong").hide();
				}else if(typeck==2){
					$(".newthumb").show();
					$(".box").show();
					$(".putong").hide();
				}else if(typeck==3){
					$(".gold").show();
					$(".newthumb").hide();
					$(".box").hide();
					$(".else").hide();
				}else if(typeck==4){
					$(".newthumb").hide();
					$(".box").hide();
					$(".putong").hide();
				}else if(typeck==5){
					$(".changci").show();
					$(".xc").show();
					$(".time").hide();
					$(".jf").hide();
					$(".newthumb").hide();
					$(".box").hide();
				}else if(typeck==6){
					$(".xs").show();
					$(".time").show();
					$(".changci").hide();
					$(".jf").hide();
					$(".newthumb").hide();
					$(".box").hide();
				}else if(typeck==7){
					$(".jf").show();
					$(".changci").show();
					$(".time").hide();
					$(".xs").hide();
					$(".xc").hide();
					$(".newthumb").hide();
					$(".box").hide();
				}else{
					$(".newthumb").hide();
					$(".box").hide();
					$(".putong").show();
				}
				var shopck = $("input[name='shop']:checked").val();
				if(shopck==1){
					$(".price").show();
				}else{
					$(".price").hide();
				}
				
				form.on('radio(types)', function(data){
					if(data.value==1){
						$(".newthumb").hide();
						$(".box").show();
						$(".putong").hide();
					}else if(data.value==2){
						$(".newthumb").show();
						$(".box").show();
						$(".putong").hide();
					}else if(data.value==3){
						$(".newthumb").hide();
						$(".gold").show();
						$(".else").hide();
					}else if(data.value==4){
						$(".newthumb").hide();
						$(".box").hide();
						$(".putong").hide();
					}else if(data.value==5){
						$(".changci").show();
						$(".xc").show();
						$(".time").hide();
						$(".jf").hide();
						$(".newthumb").hide();
						$(".box").hide();
						$(".gold").hide();
					}else if(data.value==6){
						$(".xs").show();
						$(".time").show();
						$(".changci").hide();
						$(".jf").hide();
						$(".newthumb").hide();
						$(".box").hide();
						$(".gold").hide();
					}else if(data.value==7){
						$(".jf").show();
						$(".changci").show();
						$(".time").hide();
						$(".xs").hide();
						$(".xc").hide();
						$(".newthumb").hide();
						$(".box").hide();
					}else{
						$(".newthumb").hide();
						$(".box").hide();
						$(".putong").show();
					}
				});
				form.on('radio(shop)', function(data){
					if(data.value==1){
						$(".price").show();
					}else{
						$(".price").hide();
					}
				});
				form.on('submit(rankadd)', function(data) {
					$.ajax({
			            url:"{php echo $this->createWebUrl('propdo');php}",
			            data:$('#form').serialize(),
			            type:"post",
			            dataType:"json",
			            success:function(data){
			            	if(data.code=='1'){
			                	layer.alert(data.msg, {icon: 6},function(index){
			                		var index = parent.layer.getFrameIndex(window.name);
			                		parent.layer.close(index)
			                	});
								
			            	}else{
			                	layer.alert(data.msg, {icon: 5});
			            	}
			            },
			            error:function(data){
			                layer.alert('请稍后重试', {icon: 5});
			            }
			        });
					return false;
				});
  
				 //普通图片上传
				layui.upload({
					elem: '#thumb',
					url: '{php echo $this->createWebUrl("Uploadimg");php}',
					success: function(res){
						if(res.code==1){
							$('#show').attr('src', res.path);
							$('#thumbs').val(res.path);
						}
					}
				});  
				$(".del").click(function(){
					var id = $(this).attr('data-id');
					var remark = $("#remark").val();
					newremark = remark.split(",");
					var index = newremark.indexOf(id);
					if (index > -1) {
					    newremark.splice(index, 1);
					}
					var res = newremark.join(",");
					$("#remark").val(res);
					$(this).parent().parent().remove()
				})
				$("#addlibrary").click(function(){
					layer.open({
					  type: 2,
					  area: ['900px', '650px'],
					  fixed: false, //不固定
					  maxmin: true,
					  content: './index.php?c=site&a=entry&do=selectprop&m=hc_answer',
					  btn: ['确定','关闭'],
                      yes: function(index){
					  		var res = window["layui-layer-iframe" + index].callbackdata();
					  		var alr = $("#remark").val();
					  		if(alr!=''){
					  			$("#remark").val(alr+','+res)
					  		}else{
					  			$("#remark").val(res)
					  		}
							var html = '';
							$.ajax({
					            url:"{php echo $this->createWebUrl('propdo');php}",
					            data:{ids:res,act:'ajaxlook'},
					            type:"post",
					            dataType:"json",
					            success:function(data){
					            	layui.each(data.data, function(index, item){
					            		html += '<tr>';
								      	html += '<td>'+item.name+'</td>';
								      	html += '<td><img style="width:50px" src="'+item.thumb+'"></td>';
								      	html += '<td>'+item.cc+'</td>';
								      	html += '<td>'+item.sj+'</td>';
								      	html += '<td>'+item.jb+'</td>';
								      	html += '<td>'+item.jy+'</td>';
								      	html += '<td>'+item.price+'</td>';
								      	html += '</tr>';
								    });
								    $("tbody").append(html);
					            },
					            error:function(data){
					                layer.alert('请稍后重试', {icon: 5});
					            }
					        });

	                        //最后关闭弹出层
	                        layer.close(index);
	                    },
	                    cancel: function(){
	                        //右上角关闭回调
	                    }
					});
				})

			});
		</script>

	</body>

</html>